﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
	public class CourseInfoConfig : IEntityTypeConfiguration<CourseInfo>
	{
		public void Configure(EntityTypeBuilder<CourseInfo> builder)
		{
			builder.ToTable("T_Course");
			builder.Property(c => c.CourseName).HasMaxLength(20).IsRequired();
			builder.Property(c => c.StartTime).IsRequired();
			builder.Property(c => c.EndTime).IsRequired();
			builder.Property(c => c.Description).HasMaxLength(100);

			builder.HasOne<ClassInfo>(c => c.Location).WithOne(c => c.Course).HasForeignKey<ClassInfo>(d => d.Id);

			builder.HasMany<StudentInfo>(c => c.StudentList).WithMany(s => s.CourseList).UsingEntity(a => a.ToTable("T_Students_Courses"));

		}
	}
}
